#!/usr/bin/env python3

import os

import shutil

def copy_directory(source, destination):
    shutil.copytree(source, destination)

def get_supported_kernel_version(directory):
    for root, dirs, files in os.walk(directory):
        supported_kernel_versions = dirs
        return supported_kernel_versions

def get_supported_template(kernel_module_path):
    for root, dirs, files in os.walk(kernel_module_path):
        return dirs



def main():
    supported_kernel_version = get_supported_kernel_version('./templates')
    
    while True :
        print(f"支持的内核版本:{supported_kernel_version}")
        kernel_version = input("输入内核版本：")
        if kernel_version in supported_kernel_version :
            break
        
    kernel_module_path = os.path.join('./templates',kernel_version)
    supported_tempalte = get_supported_template(kernel_module_path)
    while True :
        print(f"支持的模板:{supported_tempalte}")
        input_template = input("请选择模板:")
        if input_template in supported_tempalte :
            break


    template_path = os.path.join(kernel_module_path,input_template)
    copy_path = os.path.join('./',input_template)
    print(f"初始化模板：<linux-{kernel_version}>:<{input_template}>")    
    try :
        copy_directory(template_path,copy_path)
        print(f'代码路径：{copy_path}')
    except Exception as e :
        print(f"异常：{e}")



if __name__ == "__main__":
    main()
